<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Auth {
    var $CI;
    var $_model;

    function __construct(){

        $this->CI = get_instance();
        $this->CI->load->library('session');
        $this->CI->load->model("user_model");
    }

    function is_Admin(){

        $info = $this->CI->user_model->getInfo($this->CI->session->userdata("userid"));

        if($this->is_Login() && $info['level']==1){
            return TRUE;
        }
        else{
            return FALSE;
        }
    }

    function is_Active($userid)
    {
        if($this->CI->user_model->actived($userid))
            return TRUE;
        else
            return FALSE;
    }

    function is_Login(){

        if($this->CI->session->userdata("username") && $this->CI->session->userdata("username")!=""
            && $this->CI->session->userdata("userid") && $this->CI->session->userdata("userid")!="")
            return TRUE;
        else
            return FALSE;
    }

    function set_userdata($data)
    {
        $this->CI->session->set_userdata($data);
    }

    function __get($var)
    {
        return $this->CI->session->userdata($var);

    }
} 